<?php
/**
 * Created by PhpStorm.
 * User: Jiarui
 * Date: 2015/10/28
 * Time: 1:13
 */

namespace Home\Controller;
use Think\Controller;
use Think\Exception;
use Think\Log;

class RouteController extends Controller
{
    public function index(){

        $this->display();

    }

    public function getRouteList(){

        $title = I('get.title/s');

        $route_model = D('Route');

        try {

            $data = $route_model->getRoute($title,9);

        }catch (Exception $e){

            $this->ajaxReturn(array('state'=>'0','show'=>0));

        }

        $data->state = 1;

        $this->ajaxReturn($data);

    }

    public function subDate($data){
        return date('Y-m-d',strtotime($data));
    }

    public function readRoute(){

        $id = $_GET['id'];
        $url = $_GET['url'];
        $result = D('Route')->getRouteById($id);
        $result['starttime']=$this->subDate($result['starttime']);
        $result['endtime']=$this->subDate($result['endtime']);
        if(empty($url))
            $result['img_url'] = implode('/',array('uploads','routeImage',$result['img_url']));
        else $result['img_url'] = implode('/',array('uploads_tmp','route',$url));
        $this->assign('route',$result);
        $this->display();
//        $this->ajaxReturn($result);

    }
}